/*
 * FilePath     : \src\main.ts
 * Author       : SJZ
 * Date         : 2025-03-12 19:28
 * LastEditors  : SJZ
 * LastEditTime : 2025-03-28 23:59
 * Description  : 系统入口
 * CodeIterationRecord:
 */

import "@/assets/iconfont/iconfont.css";
import "@/assets/scss/index.scss";
import { i18n } from "@/i18n/index"; // i18n国际化
import { mockRequest } from "@/mock/index";
import installPinia from "@/stores/pinia"; // 状态管理
import directives from "@/utils/directives"; // 自定义指令
import "@/utils/setting.ts";
import elementPlus, { ElDialog, ElDrawer } from "element-plus";
import "element-plus/dist/index.css";
import locale from "element-plus/es/locale/lang/zh-CN"; //中文
import { createApp } from "vue";
import app from "./App.vue";
import { installRouter } from "./router"; // 路由
import "uno:components.css";
import "virtual:uno.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import autofit from "autofit.js";
// 初始化配置
initSetting();
const setupApp = async () => {
  // 判断是否未moke模式
  if (common.storage("mockMode")) {
    mockRequest();
  }
  // 创建实例
  const appInstance = createApp(app);
  appInstance.config.errorHandler = (err, vm, info) => {
    console.error("Global Error Handler:", err, vm, info);
  };
  installPinia(appInstance);
  // 屏幕自适应添加
  autofit.init({
    dw: 1920,
    dh: 1080,
    el: "#app",
    ignore: [
      {
        el: ".el-select__popper",
        scale: 0.9
      }
    ]
  });
  await installRouter(appInstance);
  appInstance.use(directives).use(i18n).use(elementPlus, { size: "small", zIndex: 3000, locale }).mount("#app");
  document.documentElement.classList.add("primary");
  // 设置全局属性 弹窗默认点击遮罩层不关闭
  ElDrawer.props.closeOnClickModal.default = false;
  ElDialog.props.closeOnClickModal.default = false;
};

setupApp();
